﻿Ext.define('app.system.maildefined.Index', {
    extend: 'Ext.panel.Panel',
    border: true,
    scrollable:'y',
    tbar: [],
    initComponent: function () {
        var me = this;
        me.items = [
            {
                xtype: 'container',
                layout: 'hbox',
                anchor: '100%',
                items: [
                    me.getMailForm(),
                    me.getFormatRemark()
                ]
            }
        ];
        me.tbar = [
            {
                xtype: 'combo',
                width:300,
                editable: false,
                fieldLabel: '邮件类别',
                store: Ext.create("app.ux.PrmStore", { url: '/api/services/app/mailDefined/GetMailCategory' }),
                queryMode: 'local',
                displayField: 'key',
                valueField: 'value',
                listeners: {
                    select: function (cbo, record, index) {
                        me.initform(cbo.getValue());
                    }
                }
            },
            "->",
            {
                text: '保存',
                icon: '/Content/images/page_save.png',
                handler: function () {
                    var valJson = me.getMailForm().getForm().getValues();
                    App.AjaxPut('/api/services/app/mailDefined/updateMailDefined', valJson, function (data) {
                        Ext.Msg.alert("系统提示", "设置成功");
                    });
                }
            }
        ];
        me.callParent();
    },
    initform: function (category) {
        var me = this;
        App.AjaxGet('/api/services/app/mailDefined/GetMail?category=' + category, function (data) {
            me.getMailForm().getForm().setValues(data.result);
        });
    },
    getMailForm: function () {
        var me = this;
        if (!this.mailForm) {
            this.mailForm = new Ext.form.Panel({
                defaultType: 'textfield',
                border: false,
                flex: 2,
                defaults: { anchor: '100%' },
                fieldDefaults: {
                    labelWidth: 90,
                    labelAlign: "right",
                    flex: 1,
                    margin: 6
                },
                items: [
                    { xtype: 'hidden', name: 'id' },
                    { fieldLabel: '主题', name: 'subject' },
                    {
                        xtype: 'combo',
                        fieldLabel: '优先级',
                        name: 'priority',
                        store: Ext.create('Ext.data.Store', {
                            fields: ['name', 'id'],
                            data: [
                                { "name": "Normal", "id": "0" },
                                { "name": "Low", "id": "1" },
                                { "name": "High", "id": "2" }
                            ]
                        }),
                        queryMode: 'local',
                        displayField: 'name',
                        valueField: 'id'
                    },
                    {
                        xtype: 'tagfield',
                        name: 'projectRoles',
                        fieldLabel: '项目角色',
                        store: Ext.create("app.ux.PrmStore", { url: '/api/services/app/projectRole/GetAll' }),
                        typeAhead: false,
                        minChars: 1,
                        queryMode: 'local',
                        displayField: 'roleName',
                        valueField: 'id'
                    },
                    new Ext.form.RadioGroup({
                        fieldLabel: '作用范围',
                        columns: 5,
                        vertical: true,
                        items: [
                              { boxLabel: 'Null', name: 'optScope', inputValue: 0 },
                              { boxLabel: 'all', name: 'optScope', inputValue: 99, checked: true },
                              { boxLabel: 'business', name: 'optScope', inputValue: 77 },
                              { boxLabel: 'center', name: 'optScope', inputValue: 22 },
                              { boxLabel: 'room', name: 'optScope', inputValue: 11 },
                        ]
                    }),
                    {
                        xtype: 'tagfield',
                        name: 'systemRoles',
                        fieldLabel: '系统角色',
                        store: Ext.create("app.ux.PrmStore", { url: '/api/services/app/role/GetAll' }),
                        typeAhead: false,
                        minChars: 1,
                        queryMode: 'local',
                        displayField: 'name',
                        valueField: 'id'
                    },
                    {
                        xtype: 'textarea',
                        height: 100,
                        emptyText: '分号分割',
                        fieldLabel: '自定义收件人',
                        name: 'receivers'
                    },
                    {
                        xtype: 'textarea',
                        height: 200,
                        fieldLabel: '正文',
                        name: 'body'
                    },
                    {
                        xtype: 'textarea',
                        height: 200,
                        hidden: true,
                        fieldLabel: '备注',
                        name: 'notes'
                    }
                ]
            });
        }
        return this.mailForm;
    },
    getFormatRemark: function () {
        if (!this.formatRemark) {
            this.formatRemark = new Ext.panel.Panel({
                border: false,
                flex: 1,
                bodyStyle: 'padding:10px;',
                items: [
                    { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">文档上传参数：</a>' },
                    { border: false, html: '[项目名称] - [项目编号] - [产品号] - [操作人]- [操作时间] - [文档类别] - [文档名称]  ' },

                    { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目问题提问参数：</a>' },
                    { border: false, html: '[项目名称] - [项目编号] - [产品号] - [操作人]- [操作时间]- [标题]- [内容]   ' },

                    { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目问题解答参数：</a>' },
                    { border: false, html: '[项目名称] - [项目编号] - [产品号] - [操作人]- [操作时间] - [标题]- [内容]- [回答]' },

                    { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目状态变更参数：</a>' },
                    { border: false, html: '[项目名称] - [项目编号] - [产品号] - [操作人]- [操作时间]- [报告时间]- [之前状态]- [当前状态]- [之前进度]- [当前进度]- [之前预期完成]- [当前预期完成]- [描述]   ' },

                    { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">申请查看项目参数：</a>' },
                    { border: false, html: '[项目名称] - [项目编号] - [产品号] - [操作人]- [操作时间] - [审批人] - [生效时间] - [失效时间] - [申请说明]   ' },

                    { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">申请查看项目通过参数：</a>' },
                    { border: false, html: '[项目名称] - [项目编号] - [产品号] - [操作人]- [操作时间]  - [申请人] - [生效时间] - [失效时间] - [审核说明] ' },

                    { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">申请查看项目驳回参数：</a>' },
                    { border: false, html: '[项目名称] - [项目编号] - [产品号] - [操作人]- [操作时间]  - [申请人] - [审核说明]   ' },

                    { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">新增项目通知参数：</a>' },
                    { border: false, html: '[项目名称] - [项目编号] - [产品号] - [操作人]- [操作时间]- [负责人]   ' },


                    { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">询盘评估提醒：</a>' },
                    { border: false, html: '[询盘数量] - [询盘明细]-[备注]' },
                     { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">询盘评估完成提醒：</a>' },
                    { border: false, html: '[九洲代号] - [项目流水号] - [负责人]' },
                     { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">询盘评估完成提醒：</a>' },
                    { border: false, html: '[九洲代号] - [项目流水号] - [销售人员]' },

                   { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目任务更新通知：</a>' },
                    { border: false, html: '[项目名称] - [项目编号] - [问题]' },

                    { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目任务完成通知：</a>' },
                    { border: false, html: '[项目名称] - [项目编号] - [问题]' },

                     { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目任务到期未归档通知：</a>' },
                    { border: false, html: '[待归档任务明细] - [项目编号] - [待归档任务数]' },

                                  { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目计划开始通知：</a>' },
                    { border: false, html: '[将开始计划明细] - [项目编号] - [将开始计划数]' },

                                  { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目计划到期未完成通知：</a>' },
                    { border: false, html: '[应该完成计划明细] - [项目编号] - [应该完成计划数]' },
                       { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目周报完成情况：</a>' },
                    { border: false, html: '[明细] - [项目编号]' },
                        { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目报告提交提醒：</a>' },
                    { border: false, html: '[报告内容] - [项目编号]' },

                       { border: false, html: '<a style="background-color:blue;color: white;font-size:17px">项目阶段进展计划完成提醒：</a>' },
                    { border: false, html: '[待完成阶段] - [待完成阶段数]' },
                ]
            });
        }
        return this.formatRemark;
    }
})